package top.kaoshanji.p2ch18a;

import top.kaoshanji.p2ch18a.support.TaskA1;
import top.kaoshanji.p2ch18a.support.TaskB1;

import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

/**
 * 代码清单-p2ch18a-525页a：ScheduledExecutorService异常示例
 * author kaoshanji
 * ^_^
 * create time 2025/2/27 18:01
 */
public class ScheduledException {


    public static void main(String[] args) {

        ScheduledExecutorService timer = Executors.newSingleThreadScheduledExecutor();

        // 都是每秒执行一次
        // TaskB1两秒后执行，但一执行就抛出异常
        timer.scheduleWithFixedDelay(new TaskA1(), 0, 1, TimeUnit.SECONDS);
        timer.scheduleWithFixedDelay(new TaskB1(), 2, 1, TimeUnit.SECONDS);

    }


}
